package leetcode.editor.cn;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author Administrator
 * @description 表示一个折线图的最少线段数
 * @date 2023/3/24 0024
 */
public class Solution2280 {

    public static void main(String[] args) {
        Solution2280 solution2280 = new Solution2280();
        System.out.println(solution2280.minimumLines(new int[][]{{1, 1}}));
    }

    public int minimumLines(int[][] stockPrices) {
        int len = stockPrices.length;
        if (len == 1) {
            return 0;
        }else if(len == 2) {
            return 1;
        }
        Arrays.sort(stockPrices, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[0] - o2[0];
            }
        });
        int ans = 1;
        for (int i = 2; i < len; i++) {
            if ((stockPrices[i][0] - stockPrices[i-1][0])*(stockPrices[i][1] - stockPrices[i-2][1]) ==
                    (stockPrices[i][0] - stockPrices[i-2][0])*(stockPrices[i][1] - stockPrices[i-1][1])) {
                continue;
            }else {
                ans++;
            }
        }
        return ans;
    }

}
